<template>
	<view class="content">
		<view class="header">
			<image src="/static/images/login/title.png"></image>
		</view>
		<view class="form-con">
			<view class="list">
				<view class="list-call" :class="activeValue.userNameActive? 'list-call-active' : ''">
					<image class="img" src="/static/images/login/user.png"></image>
					<input class="sl-input" v-model="userName" type="text" maxlength="32" placeholder="输入账号"
						placeholder-style="color:#eaeaea" @blur="blurInput('userNameActive')"
						@focus="focusInput('userNameActive')" />
				</view>
				<view class="list-call" :class="activeValue.passWord? 'list-call-active' : ''">
					<image class="img" src="/static/images/login/password.png"></image>
					<input class="sl-input" v-model="password" type="text" maxlength="32" placeholder="输入密码"
						password="true" placeholder-style="color:#eaeaea" @blur="blurInput('passWord')"
						@focus="focusInput('passWord')" />
				</view>
			</view>

			<view class="button-login" hover-class="button-hover" @tap="bindLogin()">
				<text>登录</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '@/api/systemApi.js';
	export default {
		data() {
			return {
				userName: 'yanghaoxing1',
				password: 'Geofly@123456',
				activeValue: {
					userNameActive: false,
					passWord: false,
				}
			};
		},
		methods: {
			focusInput(value) {
				this.activeValue[value] = true;
			},
			blurInput(value) {
				this.activeValue[value] = false;
			},
			/**
			 * 获取token
			 */
			getLogin() {
				console.log('login------开始')
				const params = {
					grant_type: 'custom_password',
					password: this.password,
					username: this.userName,
				}
				// 登录
				login(params).then((res) => {
					console.log('login-登录res:', res);
					const {
						access_token,
						refresh_token,
						token_type
					} = res;
					const token = `${token_type} ${access_token}`
					uni.setStorageSync('app_token', token);
					this.$store.commit('updateToken', token);
					this.$store.commit('updateRefreshToken', refresh_token);
					console.log('token:', token);
					// setTimeout(() => {
					// 	uni.hideLoading();
					// 	//成功后的逻辑
					// 	uni.navigateTo({
					// 		url: '/pages/index/index'
					// 	});
					// }, 1500)
				}).catch((err) => {
					uni.showToast({
						icon: 'none',
						title: err
					})
				})
			},
			bindLogin() {
				if (this.userName.length == 0) {
					uni.showToast({
						icon: 'none',
						title: '账号不能为空'
					});
					return;
				}
				if (this.password.length < 6) {
					uni.showToast({
						icon: 'none',
						title: '密码不正确'
					});
					return;
				}
				uni.showLoading({
					title: '登陆中',
				})
				// this.getLogin();
				uni.setStorageSync('app_token',
					'Bearer eyJraWQiOiI0ZWQ1YzI1YS0yZWUzLTRhYjctODRkYi0xYTA2MzNkMDQxMGIiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ5YW5naGFveGluZzEiLCJhdWQiOiI0MjgyZjI2M2FkNDE0NTJhOWY3NTJhMzg2MmIzY2UyOSIsIm5iZiI6MTcxMDMwMDkxOCwic2NvcGUiOlsib3BlbmlkIl0sIm9ubGluZVVzZXIiOnsiYWN0dWFsTmFtZSI6IuadqOWPt-aYnyIsImRpc3RyaWN0Q29kZSI6IjUzMDAwMCIsIm9pZGNJZCI6Ils0MjgyZjI2M2FkNDE0NTJhOWY3NTJhMzg2MmIzY2UyOV0iLCJhdXRob3JpemF0aW9uSWQiOiI4ZDU0ZDhhMzA5OTA0ZmVhYWY0ZDNhMWI3NjE4NjU2NiIsImlwIjpudWxsLCJhdXRob3JpemF0aW9uRmxhZ0xpc3QiOltdLCJpZCI6ImI0ZTI3OGU3NTUxZDAwMGE1ZWZmNzM5NzNjZjQ2ZTY5IiwiZGlzdHJpY3RMZXZlbCI6bnVsbCwiam9iIjpudWxsLCJlbWFpbCI6bnVsbCwibmVlZFVwZGF0ZVBhc3N3b3JkIjpudWxsLCJ1c2VybmFtZSI6InlhbmdoYW94aW5nMSJ9LCJpc3MiOiJodHRwOlwvXC8xOTIuMTY4LjEuMzJcL21yLWNhcy1hcGlcL3JiYWNcLyIsImV4cCI6MTcxMDMyOTcxOCwiaWF0IjoxNzEwMzAwOTE4fQ.faB4p99QEKbeiOoVm0m4HKWdW0Z1FwbJGyhlSf-AmRPzG3mR50dL9XHpASTb8D1alDE9viSr6JVFSN-8qZ2HHTqt-u6Gd0wbDkcRPVtOBWOkSn54rIvbvPTy9etNYfUWcoyMl0-hZgbOGUoEr2VJUfX8D0KQ0tNnOIldLmNypTRWSpx3bAhytnfjQbPYC7MfkEVR37NtNF1GF90MjeLhivl3wrgnsqEd5tLtB6AnW0vZ0aUJ2AzSZ6cpJc976Ct5mndao9utGenqXXguPxrFm64F90x9bt7Axk4CqxjN1Cabv8NUzQ_YvI0OM692AsPnc8i5udHv0E23vkMAu5I5rQ'
				)
				this.$store.commit('updateToken', uni.getStorageSync('app_token'));
				setTimeout(() => {
					uni.hideLoading();
					//成功后的逻辑
					uni.reLaunch({
						url: '/pages/index/index'
					});
				}, 1500)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		justify-content: center;
		background-image: url('/static/images/login/login_bg.png');
		background-repeat: no-repeat;
		// background-size: 100% 100%;
		height: 100vh;
		padding-bottom: 100rpx;
	}

	.header {
		width: 660rpx;
		height: 80rpx;
		margin-left: auto;
		margin-right: auto;
	}

	.header image {
		width: 100%;
		height: 100%;
	}

	.form-con {
		margin: 0 20rpx;
		padding: 0 50rpx;
		padding-top: 90rpx;
		border-radius: 10rpx;
	}

	.list {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
	}

	.list-call {
		box-sizing: border-box;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		height: 80rpx;
		margin-bottom: 50rpx;
		color: #FFF;
		border-bottom: 1rpx solid #e2e2e2;
	}

	.list-call-active {
		border-bottom: 1.5rpx solid #ffffff;
	}

	.list-call .img {
		width: 50rpx;
		height: 50rpx;
	}

	.list-call .sl-input {
		flex: 1;
		text-align: left;
		font-size: 30rpx;
		margin-left: 8rpx;
	}

	.button-login {
		color: #FFFFFF;
		font-size: 30rpx;
		width: 600rpx;
		height: 70rpx;
		background: rgba(0, 100, 200, 1);
		box-shadow: 0rpx 2rpx 5rpx 0rpx rgba(164, 217, 228, 0.1);
		border-radius: 5rpx;
		line-height: 60rpx;
		text-align: center;
		margin-left: auto;
		margin-right: auto;
		margin-top: 70rpx;
		margin-bottom: 50rpx;
	}

	.button-hover {
		background: rgba(0, 128, 255, 1.0);
	}
</style>